import { _decorator, Component, director, Node, Sprite } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('bgMapManager2')
export class bgMapManager2 extends Component {
    @property(Node)
    bg1: Node
    @property(Node)
    bg2: Node
    @property(Node)
    node2: Node;

    counttime = 0
    nowtime = 0
    endtime = 5

    state: boolean = false
    protected onLoad(): void {
        this.bg1.active = true
        this.bg2.active = false
    }

    scene2Change(sender, str) {
        if (str == 0) {
            director.loadScene('bgMap1')
        } else if (str == 1) {
            this.bg1.active = false
            this.bg2.active = true
            this.state = true
        }
    }

    update(deltaTime: number) {
        if (this.state) {
            const sprite = this.node2.getComponent(Sprite)
            console.log(this.nowtime)
            this.counttime += deltaTime
            this.nowtime = this.counttime / this.endtime
            this.nowtime = (this.nowtime > 1) ? 1 : this.nowtime
            sprite.fillRange = this.nowtime
            if (this.nowtime == 1) {
                director.loadScene('scene-2d')
            }

        }
    }
}


